<?php

namespace App\Console\Commands;

use App\Models\Customer;
use App\Models\Pocket;
use Illuminate\Console\Command;

class SeederTestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 's';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'seeder test data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->seederPocketLog();
    }

    public function seederPocketLog($n = 10)
    {
        $users = Customer::all();

        foreach ($users as $user) {
            $pocket = Pocket::query()->firstOrCreate([
                'customer_id' => $user->id,
            ]);

            for ($i = 0; $i < $n; $i++) {
                $amount = rand(100, 9999);
                if (rand(2, 5) > 3) {
                    $this->info('Recharge');
                    $pocket->recharge($amount);
                } else {
                    $this->info('Consume');
                    $pocket->consume($amount);
                }
            }
        }
    }
}
